home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Question on 'bubble sort'
- Date: Thu, 04 Apr 96 00:01:45 GMT
- Organization: none
- Message-ID: <828576105snz@genesis.demon.co.uk>
- References: <4jieso$juc@lantana.singnet.com.sg> <828206958snz@genesis.demon.co.uk> <4jmv0d$t2p@news1.mnsinc.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4jmv0d$t2p@news1.mnsinc.com> huang@mnsinc.com "Szu-Wen Huang" writes:
-
- >Lawrence Kirby (fred@genesis.demon.co.uk) wrote:
- >: In article <4jieso$juc@lantana.singnet.com.sg>
- >: s8700055@singnet.com.sg "XY Xie" writes:
- >
- >: >I came across this sorting algorithm called 'bubble sort' in a book.
- >
- >: If the book doesn't explain why there is never a good reason to use bubble
- >: sort then I suggest you get another book.
- >
- >Sure there is. If I had 5 minutes to code something that will sort
- >10 numbers, bubblesort comes in real handy. If you've ever joined
- >a programming contest you'll know what I mean.
-
- I don't want to harp too much on this. However if I was in such a situation I
- would write an insertion sort. It is simpler than all but the most naive
- bubble sort (and about on a par with that). A proper bubble sort requires
- that you note whether any swaps occurred in the inner loop or, better still,
- where the last one occurred. Insertion sort is why there is never a good
- reason to use (or teach for that matter) bubble sort.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-